angular.module('starter.services', [])

  .service('BaseService', function ($http) {
    this.loadMore = function ($this) {
      console.log('下拉操作...');
      console.log($this);
      $http.jsonp($this.url + "?page=" + $this.page + "&rows=" + settings.rows + "&callback=JSON_CALLBACK").success(function (response) {
        if (response.tngou.length > 0) {
          $this.items = $this.items.concat(response.tngou);
          $this.page++;
        } else {
          console.log("没有数据了...")
          $this.isload = true;
        }
        $this.callback();
      });
    }
    this.doRefresh = function ($this) {
      console.log("刷新操作...");
      //使用jsonp的方式请求
      $http.jsonp($this.url + "?page=1&rows=" + settings.rows + "&callback=JSON_CALLBACK").success(function (response) {
        $this.page = 2;
        $this.items = response.tngou;
        $this.callback();
        $this.isload = false;
      });
    }
  })
.service('Tab1Service',function ($http, BaseService) {
    this.getInfo = function () {
      return [
        {
          url: server.domain + '/food/list',type:'info',isload:false,
          page:1,
          items: [],
          loadMore: function () {
            BaseService.loadMore(this);
          },  
          doRefresh: function () {
            BaseService.doRefresh(this);
          },
          callback: function () {
            //回掉函数
          }
        }

      ]
    }
    this.getDetails=function(id){
      var url = server.domain + "/food/show?id=" + id + "&callback=JSON_CALLBACK";
      return $http.jsonp(url);
    }
  })

.service('Tab2Service',function ($http, BaseService) {
    this.getInfo = function () {
      return [
        {
          url: server.domain + '/cook/list',type:'info',isload:false,
          page:1,
          items: [],
          loadMore: function () {
            BaseService.loadMore(this);
          },  
          doRefresh: function () {
            BaseService.doRefresh(this);
          },
          callback: function () {
            //回掉函数
          }
        }

      ]
    }
    this.getDetails=function(id){
      var url = server.domain + "/cook/show?id=" + id + "&callback=JSON_CALLBACK";
      return $http.jsonp(url);
    }
  })

.service('LoginService', function ($http) {
  this.SLogin=function(name,password){
    var url=urls.login +"&name="+name+"&password="+password;
    return $http.jsonp(url);
  }
  this.Sregister=function(name,email,password){
    var url=urls.reg + "&email="+email+"&account="+name+"&password="+password;
    return $http.jsonp(url);
  }
  
})
.service('TabsucessService', function ($http) {
    this.getUser=function(token){
       var url=urls.user+"&access_token="+token;
       return $http.jsonp(url);
    }
})

